/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.util.List;
import model.pojo.Province;
import model.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author DucThien
 */
public class provinceDAO extends AbstractDAO<Province, String> {

    @Override
    protected Class getPOJOClass() {
        return Province.class;
    }
    
    public List<Object> getListProvince(){
        List<Object> list = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try{
            String hql = "SELECT distinct(pr.provinceId) , pr.provinceName FROM Province pr , DealLocation dl WHERE pr.provinceId=dl.provinceId ORDER BY pr.provinceId ASC";
            Query query = session.createQuery(hql);
            list = query.list();
            if(list.isEmpty() == true){
                return null;
            }
        }catch(HibernateException ex){
            System.err.println(ex);
        }finally{
            session.close();
        } 
        return list;
    }
}
